package mysql

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"taobao/appConfig"
)

var DB *gorm.DB

func Init() {
	var err error
	data := appConfig.AppConfig.Mysql
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		data.User, data.Password, data.Host, data.Port, data.Database)
	DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic(err)
	}
	fmt.Println("mysql连接成功")
	err = DB.AutoMigrate(&User{}, Shop{})
	if err != nil {
		panic(err)
	}
	fmt.Println("迁移成功")

}
